import geopy
import geopy.distance
from openpyxl import load_workbook


def get_distance_point(lat, lon, distance, direction):
    # 根据经纬度，距离，方向获得一个地点
    # param lat: 纬度
    # param lon: 经度
    # param distance: 距离（千米）
    # param direction: 方向（北：0，东：90，南：180，西：360）
    # return:
    start = geopy.Point(lat, lon)
    d = geopy.distance.geodesic(kilometers=distance)
    return d.destination(point=start, bearing=direction)


if __name__ == "__main__":
    wb = load_workbook(r'bd.xlsx')
    sheetnames = wb.sheetnames
    ws = wb[sheetnames[1]]
    lat = 38.3887931
    lon = 113.7113424
    for row in ws[2: ws.max_row]:
        row[9].value = lon
        row[10].value = lat
        p = get_distance_point(lat, lon, row[3].value / 100000, 90)
        row[11].value = p.longitude
        row[12].value = p.latitude
        lon = p.longitude
        lat = p.latitude
        print(lat, lon, row[3].value / 100000)
    wb.save(r'bd_new.xlsx')
